<div class="judul"><?php echo anchor("/user/", $title);?></div>
<script type="text/javascript">
  $(function(){
      $('#nama').autocomplete("<?php echo site_url('ajax_target/searchMemberUser');?>",
        {
            parse: function(data){
                var parsed = [];
                for (var i=0; i < data.length; i++) {
                    parsed[i] = {
                        data: data[i],
                        value: data[i].nama // nama field yang dicari
                    };
                }
                return parsed;
            },
            formatItem: function(data,i,max){
                var str='<div class=result>'+data.nama+'<br />Alamat: '+data.alamat+'</div>';
                return str;
            },
            width: 270, // panjang tampilan pencarian autocomplete yang akan muncul di bawah textbox pencarian
            dataType: 'json' // tipe data yang diterima oleh library ini disetup sebagai JSON
        }).result(
            function(event,data,formated){
                $(this).attr('value',data.nama);
                $('#idMember').val(data.id);
            }
        );
            
        $("input[type=submit]").click(function(event){
            event.preventDefault();
            if($('#nama').val() == ""){
                alert('Nama member harus diisi');
                $('#nama').focus();
                return false;
            }
            if($('#idMember').val() == ""){
                alert('Pilih nama member dengan benar');
                $('#idMember').focus();
                return false;
            }
            if($('#username').val() == ""){
                alert('Username tidak boleh kosong');
                $('#username').focus();
                return false;
            }
            if($('#username').val() != ""){
                $.ajax({
                   url: "<?php echo site_url('ajax_target/cekUsername');?>"+"/"+$('#username').val()+"/"+$('#idMember').val(),
                   cache: false,
                   type: 'POST',
                   dataType: 'json',
                   success: function(msg){
                       if(!msg.status){
                           alert('Username sudah terpakai');
                           $('#username').focus();
                           return false;
                       }else{
                           $("form input[type=submit]").unbind("click").click();
                       }
                   }
                });
            }
        })    
  })
</script>
<?php
  $flashdata = $this->session->flashdata('message');
  $messages = isset ($flashdata)?pesan($flashdata):"";
  echo "$messages";
  $form = isset ($formView)?$formView:"";
  if($form != ""){
     $this->load->view("$form"); 
  }
?>
<div class="data-list">
    <div class="floleft" style="margin: 8px 0">
    <?php
      echo addButton('user/add_user_form', 'tambah');
    ?>
    </div>    
    <table class="tabel" width="80%">
        <tr>
            <th>No</th>
            <th>Nama</th>
            <th>Username</th>
            <th>Tgl. Input</th>
            <th>Update Terakhir</th>
<!--            <th>Hak Module</th>
            <th>Hak Sub Module</th>-->
            <th>Aksi</th>
        </tr>
        <?php
            $no = $offset + 1;
            foreach ($listUser as $row){
        ?>
        <tr class="<?php echo ($no%2)?"even":"odd";?>">
            <td style="width: 3%;text-align: center"><?php echo $no++?></td>
            <td style="width: 25%"><?php echo $row['nama'];?></td>
            <td style="width:10%"><?php echo $row['username'];?></td>
            <td style="width:10%"><?php echo datefmysql($row['input_date']);?></td>
            <td style="width: 15%"><?php echo $row['last_update'];?></td>
<!--            <td><?php //echo $row['hak_module'];?></td>
            <td><?php //echo $row['hak_sub'];?></td>-->
            <td class="aksi" style="width: 15%">
                <?php
                  echo anchor('user/edit_user_form/'.$row['id'], ' ', 'class=edit title="edit"');
                  if($row['status'] == 1){
                      echo anchor('user/aktivasi/'.$row['id'].'/0',' ','class=nonaktif title="Non-aktifkan"');
                  }else{
                      echo anchor('user/aktivasi/'.$row['id'].'/1',' ','class=aktif title="Aktifkan"');
                  }
                  echo anchor('user/resetPassword/'.$row['id'],' ','class=reset title="Reset Password"');
                  echo anchor('user/edit_privilege/'.$row['id'],' ','class=privilege title="Edit privilege"');
                ?>  
            </td>
        </tr>
        <?php
            }
        ?>
    </table>
</div>
<?php
  echo "$pagination";
?>